﻿@using SelfMadeMillionaire.Web.Infrastructure.ViewModels.Admin
@using SelfMadeMillionaire.Web.Infrastructure
@using SelfMadeMillionaire.Core.Enums
@using SelfMadeMillionaire.Web.Infrastructure.Formatters
@using SelfMadeMillionaire.Web.Infrastructure.ViewModels.MailingList
@using PagedList.Mvc

@model SubscriptionPaymentsReportViewModel

<div class="table-responsive">
        @Html.HiddenFor(m => m.SortOrder)
		@if (Model.Transactions.Any())
        {
			<table class="table table-bordered tablesorter">
				<thead>
					<tr>
						<th><a href="#">First Name</a></th>
						<th><a href="#">Last Name</a></th>
						<th><a href="#">Email</a></th>
						<th><a href="#">Product</a></th>
                        <th><a href="#">Time of payment</a></th>
						<th><a href="#">Amount $</a></th>
					</tr>
				</thead>
				<tbody>
					@foreach (var item in Model.Transactions)
	                {
						<tr>
							<td>@item.Payment.Order.Subscriber.FirstName</td>
							<td>@item.Payment.Order.Subscriber.LastName</td>
							<td>@item.Payment.Order.Subscriber.Email</td>
							<td>@item.Payment.ItemName</td>
                            <td>@item.Payment.PaymentDate</td>
							<td style="text-align:right">$@item.Payment.McGross</td>
						</tr>
	                }
				</tbody>
			</table>
            @Html.PagedListPager(Model.Transactions, page => Url.Action("SubscriptionPayments", new { page, sort = Model.SortOrder }))      
        }
        else
        {
			<p>No records found.</p>
        }
</div>

<script type="text/javascript">
    $(function () {
        @if (Model.Transactions.Any())
        {
	        <text>
                $("#report-list table").tablesorter({});

                var sortRefresh = true;
	            @if(!string.IsNullOrEmpty(Model.SortOrder))
                {
                    <text>
                    sortRefresh = false;
                    setInitSort("report-list", '@(Model.SortOrder)');
                    </text>
                }

                $("#report-list table").on("sortEnd", function (event) {
                    $("#SortOrder").val(event.target.config.sortList);
                    if (sortRefresh)
                        GetList();
                    else
                        sortRefresh = true;

                });
            </text>
        }
    });

    
</script>
